home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
code
/
p_serlib.sit
/
Serial Library Source Code
/
interpret.c
< prev
next >
Wrap
Text File
|
1989-07-27
|
3KB
|
110 lines
/***********************************************************************/
/*
/* interpret.c
/* by Atul Butte
/* Copyright ⌐ 1989 by Microsoft Corporation
/* All Rights Reserved
/*
/* version 1.0
/*
/*
/* This module provides a routine which will interpret escape
/* characters in place.
/*
/***********************************************************************/
/***********************************************************************/
/*
/* interpret
/*
/***********************************************************************/
OSErr interpret( pst )
register char *pst;
{
register unsigned char cchSrc = *pst;
register unsigned char cchDest = 0;
register char *pstSrc = pst;
register char *pstDest = pst;
register char ch;
pstSrc++;
pstDest = pstSrc;
for( ; cchSrc > 0; cchSrc-- ) {
if( *pstSrc == '\\' ) {
if( cchSrc <= 1 ) {
display_error( "Not enough characters in string for \\ command." );
return( errStrFormat );
} else {
pstSrc++;
cchSrc--;
ch = *pstSrc;
switch( ch ) {
case 'n':
case 'r':
*pstDest = kchReturn;
break;
case 'b':
*pstDest = kchBackspace;
break;
case 'l':
*pstDest = kchLinefeed;
break;
case '\\':
*pstDest = '\\';
break;
case 'a':
*pstDest = kchBell;
break;
case 'x':
if( cchSrc <= 2 ) {
display_error( "Not enough digits in string for \\x." );
return( errStrFormat );
} else {
pstSrc++;
cchSrc--;
ch = *pstSrc;
if( (ch >= '0') && (ch <= '9') ) {
*pstDest = ch - '0';
} else if( (ch >= 'A') && (ch <= 'F') ) {
*pstDest = ch - 'A' + 10;
} else if( (ch >= 'a') && (ch <= 'f') ) {
*pstDest = ch - 'a' + 10;
} else {
display_error( "Invalid hex digits for \\x." );
return( errStrFormat );
}
pstSrc++;
cchSrc--;
*pstDest *= 16;
ch = *pstSrc;
if( (ch >= '0') && (ch <= '9') ) {
*pstDest += ch - '0';
} else if( (ch >= 'A') && (ch <= 'F') ) {
*pstDest += ch - 'A' + 10;
} else if( (ch >= 'a') && (ch <= 'f') ) {
*pstDest += ch - 'a' + 10;
} else {
display_error( "Invalid hex digits for \\x." );
return( errStrFormat );
}
} /* digits for \x */
break;
default:
display_error( "Invalid character after \\." );
return( errStrFormat );
} /* case */
} /* enough chars for \ */
} else { /* char is not a \ */
*pstDest = *pstSrc;
}
pstDest++;
pstSrc++;
cchDest++;
} /* repeat for all chars */
*pst = cchDest;
return( noErr );
}